import 'package:aitao_flutter/common_ui/back_nav.dart';
import 'package:aitao_flutter/common_ui/confirm_btn.dart';
import 'package:aitao_flutter/mine/controller/report_controller.dart';
import 'package:aitao_flutter/style/edgeInsets_style.dart';
import 'package:aitao_flutter/style/text_style.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../style/color_style.dart';

class ReportPage extends StatelessWidget {
  ReportPage({Key? key}) : super(key: key);
  final ReportController reportController = Get.put(ReportController());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BackNavigation(
        title: '举报',
      ),
      backgroundColor: ColorStyle.backGroundColor,
      body: GetBuilder<ReportController>(
        builder: (controller) {
          return controller.reportList.isEmpty
              ? const Center(
                  child: Text('加载中...'),
                )
              : Column(
                  children: [
                    Expanded(
                        child: Container(
                      color: ColorStyle.whiteColor,
                      margin: EdgeInsetsStyle.only(top: 10),
                      child: ListView.builder(
                        itemBuilder: (context, index) {
                          if (index == controller.reportList.length) {
                            return Container(
                                padding: EdgeInsetsStyle.all(10),
                                height: 130,
                                color: ColorStyle.whiteColor,
                                child:  TextField(
                                  controller: reportController.reasonController,
                                  maxLines: 3,
                                  maxLength: 120,
                                  decoration:const InputDecoration(
                                      border: OutlineInputBorder(),
                                      hintText: '更详细说明举报内容（选填）'),
                                ));
                          }
                          return _reportItemWidget(index);
                        },
                        itemCount: controller.reportList.isEmpty
                            ? 0
                            : controller.reportList.length + 1,
                      ),
                    )),
                    Container(
                      padding: EdgeInsetsStyle.edgeInsets(40, 10),
                      child: ConfirmButton(
                        title: '提交',
                        titleColor: ColorStyle.whiteColor,
                        backGroundColor: reportController.index == -1 ? ColorStyle.ccccccColor : ColorStyle.themeColor,
                        callBack: () {
                          reportController.submitReport();
                        },
                      ),
                    )
                  ],
                );
        },
        assignId: true,
      ),
    );
  }

  Widget _reportItemWidget(int index) {
    Map item = reportController.reportList[index];
    return GestureDetector(
      child: Container(
        color: ColorStyle.whiteColor,
        padding: EdgeInsetsStyle.edgeInsets(24, 18),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              item['name'],
              style: Styles.normalText_14,
            ),
            reportController.index == index
                ? const Icon(Icons.check_circle_rounded,
                    color: ColorStyle.mainColor)
                : const Icon(
                    Icons.circle_outlined,
                    color: ColorStyle.ashGreyColor,
                  )
          ],
        ),
      ),
      onTap: () {
        reportController.reportItemClick(index);
      },
    );
  }
}
